<?php
	require_once('../class/SanPhamDAO.php');
	require_once('../class/LoaiSanPhamDAO.php');
	require_once('../session.inc');
	$maSP = $_REQUEST['maSanPham'];
	$stt = $_REQUEST['stt'];
	$maGH = $_REQUEST['maGianHang'];
	$sanPham = SanPhamDAO::LaySanPhamTheoMa($maSP, 0);
	//$state = SanPhamDAO::CapNhatThongTinSanPham();
	$loaiSP = LoaiSanPhamDAO::LayLoaiSanPhamTheoMaLoai($sanPham->MaLoaiSP);
	$soLuongTon = $sanPham->SoLuong - SanPhamDAO::TinhSoLuongSanPhamDaMua($sanPham->Ma);
	// drop down list danh mục sàn phẩm
	$lstLoaiSP = LoaiSanPhamDAO::LayDanhSachLoaiSanPhamTheoMaGianHang($maGH);
	$danhMucSanPham = '<select name="selectDSLoaiSP" id="selectDSLoaiSPMoi">';
            
	//danh mục sản phẩm       
	if(count($lstLoaiSP)>0)
	{
		foreach($lstLoaiSP as $loaiSP)
		{
			$maLoaiSP = $loaiSP->MaLoaiSP;
			$tenLoaiSP = $loaiSP->TenLoaiSP;
			if($maLoaiSP == $sanPham->MaLoaiSP)
				$danhMucSanPham .= ' <option value="'.$maLoaiSP .'" selected="selected"">'.$tenLoaiSP .'</option>';
			else
				$danhMucSanPham .= ' <option value="'.$maLoaiSP .'">'.$tenLoaiSP .'</option>';
		}
	}
    $danhMucSanPham .= '</select>';
	//
	$btnCancelUpd = '<input name="btnHuyCapNhatSP" type="button" value="Hủy" onclick="funcHuyCapNhatSP('.$sanPham->Ma .','.$maGH.','.$stt.')"/>';
	$btnOK = '<input name="btnOk" type="button" value="Xong" onclick="funcHoanTatCapNhatSP('.$sanPham->Ma.','.$stt.')"/>';
	$check_area = '<input name="chkItem" type="checkbox" onclick="updateList1();" value="'.$sanPham->Ma.'"/>';
	$res = ' <tr id="SP'.$sanPham->Ma.'">
				<td>
					'.$check_area.'
				</td>
				<td>'.$stt.'</td>
				<td>'.$sanPham->Ma.'</td>
				<td><input id="txtTenSanPhamMoi" size="15%" type="text" value="'.$sanPham->TenSanPham.'"/></td>
				<td><input id="txtDonGiaGocMoi" size="14%" type="text" value="'.$sanPham->DonGiaGoc.'"/></td>
				<td><input id="txtDonGiaBanMoi" size="13%" type="text" value="'.$sanPham->DonGiaBan.'"/></td>
				<td>'.$soLuongTon.'</td>
				<td>'.$danhMucSanPham.'</td>
				<td>'.$btnOK.'</td>
				<td>'.$btnCancelUpd.'</td>
			</tr>
								';
	echo $res;
?>